<template>
  <div>
    <el-transfer
      v-model="value"
      :props="{
        key: 'id',
        label: 'name'
      }"
      :data="users"
      :titles="['所有用户','已选用户']"
      filterable
      :filter-method="filterMethod"
    >
    </el-transfer>
    <el-button type="primary" style="margin-top: 20px" plain @click="save()">保存</el-button>
  </div>
  
</template>
<script>
export default {
  name: "UserList",
  props: {
    roleId: {
      type: Number,
      default: null
    },
    usershow: {
      type: Boolean
    }
  },
  data () {
    return {
      users: [],
      value: [],
      filterMethod(query,item) {
        return item.name.indexOf(query) > -1;
      }
    }
  },
  created() {
    this.getUsers()
    this.getRoleUser()
  },
  methods: {
    getUsers() {
      this.$axios.get('/ums-user/getAll',{active: 1}, response => {
        this.users = response.obj
      })
    },
    getRoleUser() {
      this.$axios.get('/ums-user-role/list',{roleId: this.roleId},response => {
        for(let i = 0; i < response.obj.length; i++) {
          this.value.push(response.obj[i].userId)
        }
      })
    },
    save() {
      this.$axios.post('/ums-user-role/save',
      {value: this.value, roleId: this.roleId},
      () => {
        this.$emit('update:usershow',false)
      },null)
    }
  }
}
</script>
<style lang="less" scoped>
</style>